//
//  LLTextField.m
//  TaoTuo
//
//  Created by admin on 2019/8/15.
//  Copyright © 2019 admin. All rights reserved.
//

#import "LLTextField.h"

@interface LLTextField ()

@property (nonatomic, strong) UIView *lineView;

@end

@implementation LLTextField

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.bottom - 1 - self.top, self.width, 1)];
        _lineView.backgroundColor = UIColorHex(EDEDED);
        [self addSubview:_lineView];
        
        self.font = [UIFont systemFontOfSize:15];
        self.textColor = UIColorHex(333333);
        
    }
    return self;
}

- (void)setLeftImageName:(NSString *)leftImageName
{
    _leftImageName = leftImageName;
    if (_leftImageName) {
        if (self.leftView) {
            UIImageView *leftImgView = (UIImageView *)self.leftView;
            leftImgView.image = [UIImage imageNamed:leftImageName];
        } else {
            UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, self.height)];
            leftImageView.contentMode = UIViewContentModeLeft;
            leftImageView.image = [UIImage imageNamed:leftImageName];
            self.leftView = leftImageView;
            self.leftViewMode = UITextFieldViewModeAlways;
        }
    }
}

- (void)setHiddenBottomLine:(BOOL)hiddenBottomLine
{
    _hiddenBottomLine = hiddenBottomLine;
    
    self.lineView.hidden = hiddenBottomLine;
}

- (CGRect)leftViewRectForBounds:(CGRect)bounds
{
    CGFloat w = 0;
    if (self.leftImageName.length > 0) {
        w = 30;
    }
    return CGRectMake(0, 0, w, bounds.size.height);
}

- (CGRect)textRectForBounds:(CGRect)bounds
{
    
    return CGRectMake(self.leftView.right, 0, bounds.size.width - 30, bounds.size.height);
}


@end
